<?php

namespace Controller\Upload;

class Image extends \Controller\Base {

	public function actionIndex() {
		//上传配置
		$config = array(
			'savePath' => 'upload/' ,             //存储文件夹
			'maxSize' => 102400 ,                   //允许的文件最大尺寸，单位KB
			'allowFiles' => array( '.gif' , '.png' , '.jpg' , '.jpeg' )  //允许的文件格式
		);
		//上传文件目录
		$path = COMMON_DIR . '/uploads/';

		//背景保存在临时目录中
		$config['savePath' ] = $path;
		$up = new \Util\Uploader('upfile', $config);
		$callback = $this->getParam('callback');
		$info = $up->getFileInfo();
		$info['url'] = urlencode(str_replace($path, '', $info['url']));
		/**
		 * 返回数据
		 */
		if($callback) {
			echo '<script>'.$callback.'('.json_encode($info).')</script>';
		} else {
			echo json_encode($info);
		}
	}
}